/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.snda.dw.lidejia.partitionfilegenerator;

import org.apache.hadoop.conf.Configured;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hive.ql.io.HiveKey;
import org.apache.hadoop.io.SequenceFile;
import org.apache.hadoop.util.ReflectionUtils;
import org.apache.hadoop.util.Tool;
import org.apache.hadoop.util.ToolRunner;

/**
 *
 * @author lidejia
 */
public class PartitionerFileReader extends Configured implements Tool {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) throws Exception {
        int code = 0;
        if (args.length > 0) {
            code = ToolRunner.run(new PartitionerFileReader(), args);
        } else {
            code = -1;
            System.err.println("Missing args");
        }
        System.exit(code);
    }

    public int run(String[] args) throws Exception {
        FileSystem fs = FileSystem.get(getConf());
        try {
            SequenceFile.Reader reader = new SequenceFile.Reader(fs, new Path(args[0]), getConf());
            try {
                HiveKey key = (HiveKey) ReflectionUtils.newInstance(reader.getKeyClass(), getConf());
                while (reader.next(key)) {
                    System.out.println(key);
                }
                reader.close();
            } finally {
                reader.close();
            }
        } finally {
            fs.close();
        }
        return 0;
    }
}
